package com.collectionAndMap.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/***
 * @ClassName: Test
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 15:28 2022/2/18
 * @version : V1.0
 */
public class ArraysAsList {
    public static void main(String[] args) {
        inToLIst();
    }


    //int[] 数组转集合的标准方法
    public static void inToLIst(){
        int[] ints = {1, 2, 2, 4, 7};
        IntStream stream = Arrays.stream(ints);
        Stream<Integer> boxed = stream.boxed();
        List<Integer> intlist = boxed.collect(Collectors.toList());

        Integer remove = intlist.remove(0);
        System.out.println(remove);
        for (int anInt : intlist) {
            System.out.print(anInt+"\t");
        }
    }

    public static void toList(){
        /*
         * 数组转集合注意点！！！！！！！
         * */
        int[] ints = {1, 2, 2, 4, 7};

        List<int[]> ints1 = Arrays.asList(ints);
        System.out.println(ints1.get(0));
        for (int anInt : ints) {
            System.out.print(anInt+"\t");
        }
        System.out.println("\n"+ints1.size()+"\t");//1

        List<Integer> list2 = Arrays.stream(ints).boxed().collect(Collectors.toList());
        for (int anInt : list2) {
            System.out.print(anInt+"\t");
        }
        System.out.println("\n"+list2.size());//5


        Integer[] integers = {1, 2, 2, 4, 7};
        List<Integer> integers1 = new ArrayList<Integer>(Arrays.asList(integers));
        for (int anInt : integers1) {
            System.out.print(anInt+"\t");
        }
        System.out.println("\n"+integers1.size()+"\t");//5
    }

}
